<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>RegisterJsp.jsp</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

    <style>
        #formdiv{
           position:absolute;
           left:450px;           
        }
        
        label{
            position:relative;
         }
        .button{
            padding-left:15px;
            padding-right:15px;
            padding-top:5px;
            padding-buttom:5px;
            font-size:15px;
         }
         span{
            color:red;
            font-size:10px;
         }
    
    </style>
    
    <script>
         var flag=new Array(false,false,false,false);
    
         function init(){
            var div=document.getElementById("divform");
            var left=window.innerHeight/5;
            left=left*2;
            div.style.left=left+"px";
         }
    
         function checkAccountFormat(str){
             var num=0;
             for(var i=0;i<str.length;i++){
                var ch=str.charAt(i); 
                if((ch>='0'&&ch<='9')||(ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
                     num++;
             }
             if(num==str.length)
               return true;
             else
                return false;    
         }
         
         function checkTelnumFormat(str){
             var num=0;
             for(var i=0;i<str.length;i++){
                var ch=str.charAt(i); 
                if(ch>='0'&&ch<='9')
                     num++;
             }
             if(num==str.length)
               return true;
             else
                return false; 
         
          }
         
         function getHttpRequest(){
            if(window.XMLHttpRequest){
              return new XMLHttpRequest();
            }else
              return ActiveXObject("Microsoft.XMLHTTP");
         
         
         }
         
       
         function checkAccountExist(account){
                  var request=getHttpRequest();
             request.onreadystatechange=function(){
             
               if(request.readyState==4){
                     
                       if(request.status==200){
                           
                         var text=request.responseText;
                         if(text.indexOf("thisacountisok")==-1){
                            
                            document.getElementById("w1").innerHTML="该账号已存在";
                            document.getElementById("w1").style.display="block";
                            }
                            
                       }
                   }
             
             
             
             }
           
             var name=account.value;
             request.open("get","servlet/RegeisterServlet?flag=asyn&account="+name,true);
             request.send(null);
             
             
         }
         
         function checkAccount(account){
             flag[0]=false;
             var warning=document.getElementById("w1");
             warning.style.display="none";
             if(account.value==""){
              warning.innerHTML="*账号不得为空";
              warning.style.display="block";
               return false;
             }
             if(!checkAccountFormat(account.value)){
                warning.innerHTML="*账号必须由子母和数字组成";
                warning.style.display="block";
                return false;   
             }
            
             checkAccountExist(account);
             flag[0]=true;
             return true;
         }
         
         function checkPasswd(passwd){
            flag[1]=false;
            var warning=document.getElementById("w2");
             warning.style.display="none";
             if(passwd.value==""){
              warning.style.display="block";
               return false;
             }
             flag[1]=true;
           return true;
         }
          
          function checkPasswddu(passwddu){
              flag[2]=false;
              var warningp=document.getElementById("w2");
              var warningd=document.getElementById("w3");
              var passwd=document.getElementById("passwd");
              warningd.style.display="none";
              if(passwd.value==""){
               warningp.style.display="block";
               return false;
              }
              if(passwddu.value==""){
               warningd.innerHTML="*确认密码不得为空"
               warningd.style.display="block";
               return false;
              }
              if(passwddu.value!=passwd.value){
               warningd.innerHTML="*密码必须一致"
               warningd.style.display="block";
               return false;
              }
              flag[2]=true;
              return true;
              
          }
          
          function checkTelnum(telnum){
             flag[3]=false;
             var warning=document.getElementById("w4");
             warning.style.display="none";
             if(telnum.value==""){
              warning.innerHTML="*号码不得为空";
              warning.style.display="block";
               return false;
             }
             if(!checkTelnumFormat(telnum.value)){
                warning.innerHTML="*联系号码必须由数字组成";
                warning.style.display="block";
                return false;   
             }
             flag[3]=true;
             return true;
          }
          
          function checkAll(){
             for(var i=0;i<flag.length;i++){
                if(flag[i]==false){
                   var warning=document.getElementById("w5");
                  
                   warning.style.display="block";
                   return false;
                }
             }
             return true;
          
          
          }
          function removeWarning(){
               var warning1=document.getElementById("w5");
               var warning2=document.getElementById("w6");
                   
                   warning1.style.display="none";
                   warning2.style.display="none";
          
          }
    
    
    </script>
  </head>
  
  <body >
       <h1 >注册页面</h1> <hr/>
       <div id="formdiv" >
       <form onsubmit="return checkAll();return false" action="servlet/RegeisterServlet" onclick="removeWarning()">
          <table>
          <tr>
              <td>账&nbsp&nbsp号:</td> 
              <td><input type="text" name="account" id="account" onkeyup="checkAccount(this)"/></td> 
              <td><span id="w1" style="display:none"></span><span id="w5" style="display:none">*信息为空，或格式不正确</span></td>
            
          </tr>
          <tr>
              <td>密&nbsp&nbsp码:</td> 
              <td><input type="password" name="passwd" id="passwd" onkeyup="checkPasswd(this)"/></td>
              <td><span id="w2" style="display:none">*密码不得为空</span></td>
          </tr>
          <tr>
              <td>确认密码:</td> 
              <td><input type="password" name="passwddu" id="passwddu" onkeyup="checkPasswddu(this)"/></td>
              <td><span id="w3" style="display:none" >*密码必须一致</span></td>
          </tr>
          <tr>
              <td>联系电话:</td> 
              <td> <input type="text" name="telnum" id="telnum" onkeyup="checkTelnum(this)"/> </td>
              <td><span id="w4"  style="display:none">*号码格式错误</span><span id="w6"  >${requestScope.registerresult}</span></td>
          </tr>
          </table> 
          <br/>
          
           <input type="submit" value="注册" class="button" /> 
           &nbsp&nbsp&nbsp&nbsp
           <input type="reset" value="重置" class="button"/>
      
       </form>
       </div>
  </body>
</html>
